<?php
namespace Admin\Controller;
use Think\Controller;
class ViewController extends CommonController {
    //view 浏览历史显示 
    public function index()
    {
      $sql = 'select * from history order by access_time desc';
      $history = M()->query($sql);
      $this->assign('history',$history);

      $this->display();   
    }

    //彻底删除
    public function delete()
    {
      if (IS_POST) {
          $historyid = I('post.historyid');
          $sql = 'delete from history where id='.$historyid;
          $delete = M()->execute($sql);
          if ($delete) {
              $arr = array(
                  'error' =>0,
                  'info'=>"记录删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>1,
                  'info'=>"记录删除失败"
                  );
              echo json_encode($arr);
          }
      }  
    }

    //批量删除
    public function deletes()
    {
      //print_r($_POST);exit;
      //Array ( [arr] => Array ( [0] => 1 [1] => 2 ) )
      if (IS_POST) {
        $arr = I('post.arr');
        $ids = implode(",", $arr);

        $res = M('history')->delete($ids);
          if ($res) {
              $arr = array(
                  'error' =>0,
                  'info'=>"记录删除成功"
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' =>1,
                  'info'=>"记录删除失败"
                  );
              echo json_encode($arr);
          }

      }

    }

}